package com.wut.clock.controller;

import com.wut.clock.common.api.CommonResult;
import com.wut.clock.entity.Comment;
import com.wut.clock.service.ICommentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * @author ZYH
 * @unit D9Lab
 * @description 评论管理
 * @date 2022/6/8 15:58
 */
@RequiredArgsConstructor
@RequestMapping("/comment")
@RestController
@Api(value="评论管理器",tags = {"评论管理器"})
public class CommentController {

    private final ICommentService commentService;

    @ApiOperation("新增一条评论")
    @PostMapping("addComment")
    public CommonResult<String> addComment(@RequestBody Comment comment){
        if(commentService.addComment(comment)>0) return CommonResult.success();
        return CommonResult.failed();
    }

    @ApiOperation("删除一条评论")
    @PostMapping("deleteComment/{commentId}")
    public CommonResult<String> deleteComment(@PathVariable Integer commentId){
        if(commentService.deleteComment(commentId)>0) return CommonResult.success();
        return CommonResult.failed();
    }

    @ApiOperation("查看本人的评论记录")
    @GetMapping("getOwnCommentRecord")
    public CommonResult getOwnCommentRecord(@RequestParam(required = false) String keywords){
        return CommonResult.success(commentService.getOwnCommentRecord(keywords));
    }

}
